﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;

public class Manage_2 : MonoBehaviour
{
    public static Manage_2 instance;
    public Canvas canvas;
    public GameObject musicalNote_prefab;
    public int currentMusic = 3;
    public MusicText Scrolltext;

    //public AudioClip[,] whiteSounds = new AudioClip[7,7];
    Layout_2[] layouts;
    
    private void Awake()
    {
        instance = this;
        if(GameData.whiteSounds[0,0]==null)
        {
            AssetBundle abMain = AssetBundle.LoadFromFile(Application.streamingAssetsPath + "/musices");
            for (int i = 0; i < 7; i++)
            {
                for (int j = 0; j < 7; j++)
                {
                    GameData.whiteSounds[i, j] = GameObject.Instantiate(abMain.LoadAsset<AudioClip>(i + "" + j));
                }
            }
        }
        //加载音乐
        
        layouts = canvas.GetComponentsInChildren<Layout_2>(true);
    }

    // Start is called before the first frame update
    void Start()
    {       
        SetLayout(GameData.layoutIndex);       
        Scrolltext.SetMusic(Musices.all_music[GameData.musicIndex]);
    }

    private void Update()
    {
        if (Input.GetKeyDown(KeyCode.Escape))
        {
            SceneManager.LoadScene(0);
        }
    }

    public void SetLayout(int index)
    {        
        layouts[index].gameObject.SetActive(true);
        layouts[index].SetKeyMusic();

        if (index == 3)
        {
            layouts[index].SetCustom();
        }
    }
}
